package com.fs.m.server.domain;

import java.util.HashMap;
import java.util.Map;

/**
 * 请求上下文信息
 *
 * User: zhuguoyin
 * Date: 13-10-7
 * Time: 下午1:21
 * To change this template use File | Settings | File Templates.
 */
public class RequestContext {

    private static ThreadLocal<RequestContext> contextThreadLocal;

    private Map param;

    private Client client;

    private Map otherParam;

    static {
        contextThreadLocal = new ThreadLocal<RequestContext>();
    }

    public static void set(RequestContext context) {
        contextThreadLocal.set(context);
    }

    public static RequestContext get() {
        return contextThreadLocal.get();
    }

    public Map getParam() {
        return param;
    }

    public void setParam(Map param) {
        this.param = param;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

    public Map getOtherParam() {
        return otherParam;
    }

//    public void setOtherParam(Map otherParam) {
//        this.otherParam = otherParam;
//    }

    public void setRequestMap(Map requestMap) {
        if (this.otherParam == null) {
            this.otherParam = new HashMap();
        }
        for (Object key : requestMap.keySet()) {
            Object value = requestMap.get(key);
            if (value instanceof Object[]) {
                Object[] objs = (Object[]) value;
                if (objs.length == 1) {
                    this.otherParam.put(key, objs[0]);
                } else {
                    this.otherParam.put(key, value);
                }
            } else {
                this.otherParam.put(key, value);
            }
        }
    }
}
